package org.malred.hospital.controller;

import org.malred.hospital.common.R;

import org.malred.hospital.entity.TbDoctor;
import org.malred.hospital.entity.TbDoctor;
import org.malred.hospital.entity.TbDoctor;
import org.malred.hospital.service.DoctorService;
import org.malred.hospital.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/doctor")
public class DoctorController extends BaseController<TbDoctor> {
    @Autowired
    private DoctorService service;

    @Override
    public R<List<TbDoctor>> findAll() {
        return R.success(service.list());
    }

    @Override
    public R<TbDoctor> findById(Long id) {
        return R.success(service.getById(id));
    }

    @Override
    public R<TbDoctor> insert(@RequestBody TbDoctor dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("添加 [DoctorManagePage] 失败");
        }
    }

    @Override
    public R<TbDoctor> update(@RequestBody TbDoctor dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("修改 [DoctorManagePage] 失败");
        }
    }

    @Override
    public R<TbDoctor> delete(Long id) {
        if (service.removeById(id)) {
            return R.success(null);
        } else {
            return R.error("删除 [DoctorManagePage] 失败");
        }
    }
}
